package com.example.dynamicdatasource.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class TestService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @DS("master")
    public String test1() {
        return jdbcTemplate.queryForObject("select name from test where id = 1", String.class);
    }

    @DS("slave")
    public String test2() {
        return jdbcTemplate.queryForObject("select name from test where id = 1", String.class);
    }
}
